<template>
	<view>
		<view class="fui-header fui-header-success">
			<view class="fui-header-left" @click="result" ><text style="font-size: 32rpx"></text></view>
			<view class="title">订单发货</view>
		</view>
		<view class="status_bar"></view>
		<view class="fui-content navbar">		
			<view class="fui-cell-group">
				<view class="fui-cell">
					<view class="fui-cell-label">收件人: </view>
					<view class="fui-cell-info">{{address.realname}}</view>
				</view>
				<view class="fui-cell">
					<view class="fui-cell-label">联系电话: </view>
					<view class="fui-cell-info">{{address.mobile}}</view>
				</view>
				<view class="fui-cell">
					<view class="fui-cell-label">收货地址: </view>
					<view class="fui-cell-info newline">{{address.province}}-{{address.city}}-{{address.area}}</view>
				</view>
				<view class="fui-cell">
					<view class="fui-cell-label">详细地址: </view>
					<view class="fui-cell-info newline">{{address.address}}</view>
				</view>
			</view>
		
			<view class="fui-cell-group">
				<view class="fui-cell">
					<view class="fui-cell-label">快递公司</view>
					<view class="fui-cell-info">
						<view class="select">
							<easy-select style="width:400rpx" id="express" ref="easySelect" :value="selecValue.label" @selectOne="selectOne" :options="select"></easy-select>
						</view>
						
					</view>
			   </view>
				<view class="fui-cell">
					<view class="fui-cell-label">快递单号</view>
					<view class="fui-cell-info">
						<input type="text" placeholder="请输入快递单号" class="fui-input" value="" id="expresssn" v-model="expresssn">
					</view>
				</view>
			</view>
		
			<view class="fui-cell-group">
				<view class="fui-cell ">
					<view class="fui-cell-label ">分包裹发货</view>
					<view class="fui-cell-info right">
						<switch :color="color" style="transform:scale(0.7)" :checked="sendtype" @change="switchChange"/>
					</view>
				</view>
			</view>		
			<view class="parcel" v-if="sendtype">
				<view class="fui-cell-group">
					<view class="fui-cell">
						<view class="fui-cell-info"><text class="icon icon-gifts"></text> 发货商品</view>
					</view>
				</view>
				<view class="fui-list-group nomargin check-group">
					<checkbox-group>
						<label class="checkbox">
							<view class="fui-list" v-for="(key, index) in list" :key="index">
								<view class="fui-list-media">	
									  <checkbox  :color="color" :checked="list[index].checked"  @click="check(index)" />
								</view>
								<view class="fui-list-media round">
									<image :src="list[index].src" class="round small" onerror="this.src='../addons/ewei_shopv2/static/images/nopic100.jpg';">
								</view>
								<view class="fui-list-inner">
									<view class="title"> {{list[index].title}}-{{list[index].sale}}包</view>
									<view class="subtitle" style="color: #666;"></view>
								</view>
							</view>
						</label>
					</checkbox-group>
				</view>
			</view>		        		        
		</view>
		<view class="status_bar"></view>
		<view class="fui-navbar">
			<view class="nav-item btn btn-gray cancel-params" @click="result">取消</view>
			<view class="nav-item btn btn-success submit-params" @click="sub">保存</view>
		</view>
	</view>
</template>

<script>
	var t = getApp().globalData,
		e = t.requirejs('core');
	export default {
		data() {
			return {
				sendtype:false,
				color:'#5cb85c',
				searchfield:'ordersn',
				select:[
					{
						'label':'其他快递',
						'value':'other'
					},
				],				
				selecValue:{
					
				},
				id:'',
				expresssn:'',
				list:[],
				address:{},
				//包裹数据
				list:[
					{
						'img':'http://qiniu.91zjj.cn/images/16/merch/203/l4HL6c4hPu6U5UbxM66vuxUO7HSxqH.jpg',
						'title':'试试一号',
						'sale':'1',
						'checked':'true',
						'id':'900',
					}
					
				],
				
			}
		},
		onLoad(o){
			var t = this;
			t.id=o.id
			t.selecValue=t.select[0]
			e.get(
				'merchmanage.order.op.send', {id:t.id},
				function(e) {
					1 == e.canapply ? ((e.show = !0), t.setData(e)) : a.alert(e.message);
				},
				!1,
				!0
			);
		},
		methods: {
			sub(){
				let data={}
				let goods=[]
				data.id=this.id
				data.express=this.selecValue.name
				data.expresssn=this.expresssn
				data.expresscom=this.selecValue.label
				data.sendtype=this.sendtype
				Object.keys(this.list).map((item)=>{
					if(this.list[item].checked){
						goods.push(this.list[item].id)
					}
					
				})
				data.sendgoodsids=goods.toString()
			
				
				//订单数据
				e.post('merchmanage.order.op.send',data, function(t) {
					if(t.status==1){
						uni.showToast({
						    title: '发货成功',
							icon:"none",
						    duration: 2000
						});
						
					}else{
						uni.showToast({
						    title: t.result.message,
							icon:"none",
						    duration: 2000
						});
					}
				});
				
			},
			radioChange(e){
				
			},
			selectOne(options) {
				  this.selecValue = options
			 },
			//返回上一页
			result(){
				uni.navigateBack({
					 delta: 1
				});
			},
			switchChange(e) {
				this.sendtype = e.target.value
			},
			check(index){
				this.list[index].checked=!this.list[index].checked
			}
		
		}
	}
</script>

<style>
.fui-header .iconfont{
	color: #fff;
	font-size: 24rpx;
	padding: 0 20rpx;
}
.btn.btn-gray{
	background: #bbb;
	border-color: #bbb;
}

.fui-cell-group{
	overflow: inherit;
}
.fui-cell-group .fui-cell .fui-cell-info{
	overflow: inherit;
}
</style>
